# cars = ['bmw','audi','toyota','subaru']
# cars.sort()
# print(cars)

# cars = ['bmw','audi','toyota','subaru']
# cars.sort(reverse=True)
# print(cars)

# cars = ['bmw','audi','toyota','subaru']

# print("Here is the original list:")
# print(cars)

# print("\nHere is the sorted list:")
# print(sorted(cars))

# print("\nHere is the original list again")
# print(cars)

# cars = ['bmw','audi','toyota','subaru']
# print(cars)

# cars.reverse()
# print(cars)

# cars = ['bmw','audi','toyota','subaru']
# len(cars)

# places = ['xiamen','hainan','kunming','beijing','hangzhou']

# print("Sorted:")
# print(sorted(places))
# print("\nOriginal:")
# print(places)

# print("\nReverse sorted:")
# print(sorted(places,reverse=True))
# print("\nOriginal:")
# print(places)

# places.reverse()
# print("\nReverse:")
# print(places)
# places.reverse()
# print("\nReverse again:")
# print(places)

# places.sort()
# print("\nSort:")
# print(places)
# places.sort()
# print("\nSort again:")
# print(places)

# languages = ["Chinese","French","English","Japanese"]
# print(sorted(languages))
# languages.sort()
# print(languages)
# languages.reverse()
# print(languages)

# players = ['charles', 'martina', 'michael', 'florence', 'eli']
# print("Here are the first three players on my team:")
# for player in players[:3]:
#     print(player.title())

# my_foods = ['pizza', 'falafel', 'carrot cake']
# friend_foods = my_foods[:]
# print("My favorite foods are:")
# print(my_foods)
# print("\nMy friend's favorite foods are:")
# print(friend_foods)

# my_foods = ['pizza', 'falafel', 'carrot cake']
# friend_foods = my_foods[:]
# my_foods.append('cannoli')
# friend_foods.append('ice cream')
# print("My favorite foods are:")
# print(my_foods)
# print("\nMy friend's favorite foods are:")
# print(friend_foods)
# print("The first three items in the list are:")
# items = my_foods[:3]
# print(items)
# print("Three items from the middle of the list are:")
# items = my_foods[1:4]
# print(items)
# print("The last three items in the list are:")
# items = my_foods[len(my_foods)-3:len(my_foods)]
# print(items)

# # 这行不通:
# my_foods = ['pizza', 'falafel', 'carrot cake']
# # ❶
# friend_foods = my_foods
# my_foods.append('cannoli')
# friend_foods.append('ice cream')
# print("My favorite foods are:")
# print(my_foods)
# print("\nMy friend's favorite foods are:")
# print(friend_foods)


# my_foods = ['pizza', 'falafel', 'carrot cake']
# friend_foods = my_foods[:]
# print("My favorite foods are:")
# for food in my_foods[:]:
#     print(food)
# print("\nMy friend's favorite foods are:")
# for food in friend_foods[:]:
#     print(food)


# price = 40
# print("Is price == 40?I predict True.")
# print(price == 40)

# print("\nIs price == 30?I predict False.")
# print(price == 30)


# # 字符串
# str1 = "Helloworld"
# str2 = 'Helloworld'
# str3 = 'helloworld'
# print("Str1 == Str2?",str1 == str2)
# print("Str1 == Str3?",str1 == str3)
# # lower()
# print("Str3 == lowerStr1?",str3 == str1.lower())
# # 相等不等大于小于大于等于小于等于
# a = 10
# b = 20
# c = 10.0
# print("a==b?", a == b)
# print("a!=b?", a != b)
# print("a>b?", a > b)
# print("a<b?", a < b)
# print("a>=c?", a >= c)
# print("a<=c?", a <= c)
# #and or
# a = 93
# print("90<= a <=100?", 90<= a <=100,a>=90 and a<=100)
# print("a < 0 or a > 100?",a < 0 or a > 100)
# # 包含，不包含
# list_data = [1,2,3,4,5]
# print("If 5 in list?", 5 in list_data)
# print("If 0 not in list?", 0 not in list_data)


# alien_color = 'red'
# if alien_color == 'green':
#     print("player won 5 scores for having hunted the alien!")
# else:
#     print("player won 10 scores!")
# alien_color = 'green'
# if alien_color == 'green':
#     print("player won 5 scores for having hunted the alien!")
# else:
#     print("player won 10 scores!")

# alien_color = 'green'
# if alien_color == 'green':
#     print("the player won 5 scores!")
# elif alien_color == 'yellow':
#     print("the player won 10 scores!")
# else:
#     print("the player won 15 scores!")
# alien_color = 'yellow'
# if alien_color == 'green':
#     print("the player won 5 scores!")
# elif alien_color == 'yellow':
#     print("the player won 10 scores!")
# else:
#     print("the player won 15 scores!")
# alien_color = 'red'
# if alien_color == 'green':
#     print("the player won 5 scores!")
# elif alien_color == 'yellow':
#     print("the player won 10 scores!")
# else:
#     print("the player won 15 scores!")

# age = 19
# if age <2:
#     print("这人是个婴儿")
# elif age < 4:
#     print("这人是个幼儿")
# elif age < 13:
#     print("这人是个儿童")
# elif age < 20:
#     print("这人是青少年")
# elif age < 65:
#     print("这人是成年人")
# else:
#     print("这人是老年人")


# favorite_fruits = ["bananas","apples","oranges"]
# for i in range(0,5):
#     fruit = input()
#     if fruit in favorite_fruits:
#         print("you really like " + fruit)

# list_user = ['admin','Peter','John','Mike','Kyrie']
# username = input()
# if username == "admin":
#     print("Hello " + username + ",would you like to see a status report?")
# else:
#     print("Hello " + username + ",thank you for loggin again.")
# if list_user == []:
#     print("We need to find some users!")
# else:
#     print("Would you like to delete all the users?")
#     if input() == "Yes" or "yes":
#         print("Deleted!")
#         list_user = []

# list_num = [1,2,3,4,5,6,7,8,9]
# for i in list_num:
#     if i == 1:
#         print("1st")
#     elif i == 2:
#         print("2nd")
#     elif i == 3:
#         print("3rd")
#     else:
#         print(str(i) + "th")

# alien_0 = {'color': 'green', 'points': 5}
# print(alien_0['color'])
# print(alien_0['points'])

# alien_0 = {'color': 'green', 'points': 5}
# print(alien_0)
# alien_0['x_position'] = 0
# alien_0['y_position'] = 25
# print(alien_0)

# alien_0 = {'color': 'green'}
# print(f"The alien is {alien_0['color']}.")
# alien_0['color'] = 'yellow'
# print(f"The alien is now {alien_0['color']}.")

# alien_0 = {'x_position': 0, 'y_position': 25, 'speed': 'medium'}
# alien_0['speed'] = 'fast'
# print(f"Original position: {alien_0['x_position']}")
# # 向右移动外星人。
# # 根据当前速度确定将外星人向右移动多远。
# if alien_0['speed'] == 'slow':
#     x_increment = 1
# elif alien_0['speed'] == 'medium':
#     x_increment = 2
# else:
# # 这个外星人的移动速度肯定很快。
#     x_increment = 3
# # 新位置为旧位置加上移动距离。
# alien_0['x_position'] = alien_0['x_position'] + x_increment
# print(f"New position: {alien_0['x_position']}")

# alien_0 = {'color': 'green', 'points': 5}
# print(alien_0)
# del alien_0['points']
# print(alien_0)


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
# }
# language = favorite_languages['sarah'].title()
# print(f"Sarah's favorite language is {language}.")

# alien_0 = {'color': 'green', 'speed': 'slow'}
# print(alien_0['points'])


# alien_0 = {'color': 'green', 'speed': 'slow'}
# point_value = alien_0.get('points', 'No point value assigned.')
# print(point_value)


# person = {'first_name':'Kyrie','last_name':'Irving','age':'30','city':'Brooklin'}
# print(person)

# favorite_num = {'A':'1','B':'2','C':'3','D':'4','F':'5'}
# print(favorite_num)

# meaning = {
#     'pointer': 'value of address',
#     'variable': 'a container',
#     'array': 'a crowd of some elements of the same type',
#     'linklist': 'a list of some elements organized by link',
#     'graph': 'some elements with complex associations'
#     }
# for ele in meaning:
#     print(ele)
#     print("\t" + meaning[ele])


# user_0 = {
#     'username': 'efermi',
#     'first': 'enrico',
#     'last': 'fermi',
# }
# for key, value in user_0.items():
#     print(f"\nKey: {key}")
#     print(f"Value: {value}")


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# for name, language in favorite_languages.items():
#     print(f"{name.title()}'s favorite language is {language.title()}.")


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# for name in favorite_languages.keys():
#     print(name.title())


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# if 'erin' not in favorite_languages.keys():
#     print("Erin, please take our poll!")


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# for name in sorted(favorite_languages.keys()):
#     print(f"{name.title()}, thank you for taking the poll.")


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# print("The following languages have been mentioned:")
# for language in set(favorite_languages.values()):
#     print(language.title())

# meaning = {
#     'pointer': 'value of address',
#     'variable': 'a container',
#     'array': 'a crowd of some elements of the same type',
#     'linklist': 'a list of some elements organized by link',
#     'graph': 'some elements with complex associations'
#     }
# for key, value in meaning.items():
#     print(f"\"{key}\" means:")
#     print(f"\t{value}")

# rivers = {
#     'Nile': 'Egypt',
#     'Amazon': 'Brazil',
#     'Yangtze': 'China (Mainland)',
# }
# for river, country in rivers.items():
#     print(f"The {river} runs through {country}.")
# for river in rivers.keys():
#     print(river)
# for country in rivers.values():
#     print(country)


# favorite_languages = {
#     'jen': 'python',
#     'sarah': 'c',
#     'edward': 'ruby',
#     'phil': 'python',
#     }
# namelist = {
#     'jen', 'sarah', 'edward', 'phil', 'michael', 'kyrie'
# }
# for name in namelist:
#     if name in favorite_languages.keys():
#         print(f"Thank you for your participation, {name.title()}!")
#     else:
#         print(f"Hey, {name.title()}.Welcome to take part in our survey!")

# # 创建一个用于存储外星人的空列表。
# aliens = []
# # 创建30个绿色的外星人。
# for alien_number in range(30):
#     new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
#     aliens.append(new_alien)
# for alien in aliens[:3]:
#     if alien['color'] == 'green':
#         alien['color'] = 'yellow'
#         alien['speed'] = 'medium'
#         alien['points'] = 10
# # 显示前5个外星人。
# for alien in aliens[:5]:
#     print(alien)


# # 存储所点比萨的信息。
# pizza = {
#     'crust': 'thick',
#     'toppings': ['mushrooms', 'extra cheese'],
#     }
# # 概述所点的比萨。
# print(f"You ordered a {pizza['crust']}-crust pizza with the following toppings:")
# for topping in pizza['toppings']:
#     print("\t"+topping)

# favorite_languages = {
#     'jen': ['python', 'ruby'],
#     'sarah': ['c'],
#     'edward': ['ruby', 'go'],
#     'phil': ['python', 'haskell'],
#     }
# for name, languages in favorite_languages.items():
#     print(f"\n{name.title()}'s favorite languages are:")
#     for language in languages:
#         print(f"\t{language.title()}")


# users = {
#     'aeinstein': {
#         'first': 'albert',
#         'last': 'einstein',
#         'location': 'princeton',
#         },
#     'mcurie': {
#         'first': 'marie',
#         'last': 'curie',
#         'location': 'paris',
#         },
#     }
# for username, user_info in users.items():
#     print(f"\nUsername: {username}")
#     full_name = f"{user_info['first']} {user_info['last']}"
#     location = user_info['location']
#     print(f"\tFull name: {full_name.title()}")
#     print(f"\tLocation: {location.title()}")


# pets = {
#     "狗": "张三",
#     "猫": "李四",
#     "鱼": "王五",
# }

# for pet,owner in pets.items():
#     print("宠物类型：",pet)
#     print("主人名字：",owner)
#     print()

# cities = {
#     "北京": {
#         "country": "中国",
#         "population": 21542000,
#         "fact": "北京是中国的首都和最大的城市。"
#     },
#     "东京": {
#         "country": "日本",
#         "population": 37400068,
#         "fact": "东京是日本的首都和最大城市。"
#     },
#     "纽约": {
#         "country": "美国",
#         "population": 8623000,
#         "fact": "纽约是美国的大城市之一，也是金融、商业和文化中心。"
#     }
# }
# for city, info in cities.items():
#     print(city+":")
#     print(f"\t国家: {info['country']}")
#     print(f"\t人口: {info['population']}")
#     print(f"\t事实: {info['fact']}")

# def greet_user():
#     """显示简单的问候语。"""
#     print("Hello!")
# greet_user()


# def greet_user(username):
#     """显示简单的问候语。"""
#     print(f"Hello, {username.title()}!")
# greet_user('jesse')


# def display_message():
#     print("函数")
# display_message()


# def favorite_book(book):
#     print(f"One of my favorite books is {book}.")
# favorite_book('Flipped')


# def describe_pet(animal_type, pet_name):
#     """显示宠物的信息。"""
#     print(f"\nI have a {animal_type}.")
#     print(f"My {animal_type}'s name is {pet_name.title()}.")
# describe_pet('hamster', 'harry')


# def describe_pet(animal_type, pet_name):
#     """显示宠物的信息。"""
#     print(f"\nI have a {animal_type}.")
#     print(f"My {animal_type}'s name is {pet_name.title()}.")
# describe_pet( pet_name='harry', animal_type='hamster')


# def describe_pet(pet_name, animal_type='dog'):
#     """显示宠物的信息。"""
#     print(f"\nI have a {animal_type}.")
#     print(f"My {animal_type}'s name is {pet_name.title()}.")
# describe_pet(pet_name='willie')


# def describe_pet(pet_name, animal_type='dog'):
#     """显示宠物的信息。"""
#     print(f"\nI have a {animal_type}.")
#     print(f"My {animal_type}'s name is {pet_name.title()}.")

# # 一条名为Willie的小狗。
# describe_pet('willie')
# describe_pet(pet_name='willie')
# # 一只名为Harry的仓鼠。
# describe_pet('harry', 'hamster')
# describe_pet(pet_name='harry', animal_type='hamster')
# describe_pet(animal_type='hamster', pet_name='harry')


# def describe_pet(animal_type, pet_name):
#     """显示宠物的信息。"""
#     print(f"\nI have a {animal_type}.")
#     print(f"My {animal_type}'s name is {pet_name.title()}.")
# describe_pet()


# def make_shirt(size, words = "I love Python"):
#     print(f"There are \"{words}\" on the shirt in size {size}.")

# make_shirt(size = "large")
# make_shirt(size = "medium")
# make_shirt(size = "small", words = "Keep fighting!")


# def describe_city(city, country = 'China'):
#     print(f"{city} is in {country}.")

# describe_city('Beijing')
# describe_city('Xi\'an')
# describe_city('London', 'UK')


# class Dog:
#     """一次模拟小狗的简单尝试。"""
#     def __init__(self, name, age):
#         """初始化属性name和age。"""
#         self.name = name
#         self.age = age
#     def sit(self):
#         """模拟小狗收到命令时蹲下。"""
#         print(f"{self.name} is now sitting.")
#     def roll_over(self):
#         """模拟小狗收到命令时打滚。"""
#         print(f"{self.name} rolled over!")



# my_dog = Dog('Willie', 6)
# your_dog = Dog('Lucy', 3)
# print(f"My dog's name is {my_dog.name}.")
# print(f"My dog is {my_dog.age} years old.")
# my_dog.sit()
# print(f"\nYour dog's name is {your_dog.name}.")
# print(f"Your dog is {your_dog.age} years old.")
# your_dog.sit()


class Car:
    """一次模拟汽车的简单尝试。"""

    def __init__(self, make, model, year):
        """初始化描述汽车的属性。"""
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0
    def get_descriptive_name(self):
        """返回整洁的描述性信息。"""
        long_name = f"{self.year} {self.make} {self.model}"
        return long_name.title()
    def read_odometer(self):
        """打印一条指出汽车里程的消息。"""
        print(f"This car has {self.odometer_reading} miles on it.")
    def update_odometer(self, mileage):
        """将里程表读数设置为指定的值。"""
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")
    def increment_odometer(self, miles):
        """将里程表读数增加指定的量。"""
        self.odometer_reading += miles

class ElectricCar(Car):
    """电动汽车的独特之处。"""
    def __init__(self, make, model, year):
        """初始化父类的属性。"""
        super().__init__(make, model, year)
        self.battery_size = 75
    def describe_battery(self):
        """打印一条描述电瓶容量的消息。"""
        print(f"This car has a {self.battery_size}-kWh battery.")

my_tesla = ElectricCar('tesla', 'model s', 2019)
print(my_tesla.get_descriptive_name())
my_tesla.describe_battery()
